using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace DebugConsole.Components
{
    /// <summary>
    /// A DebugComponent will be called by the DebugConsole
    /// pretty much like a DrawableGameComponent gets called
    /// by Xna. Actually DebugComponents could be DrawbleGameComponents
    /// but that would be messy for the host application.
    /// </summary>
    public abstract class DebugComponent 
    {
        private IContainGameInfo gameInfo;
        private DebugSharedResources resources;

        /// <summary>
        /// The list of command this component handles.
        /// </summary>
        private List<String> commands;

        protected IContainGameInfo GameInfo
        {
            get { return gameInfo; }
        }
        protected DebugSharedResources Resources
        {
            get { return resources; }
        }

        #region Constructors
        public DebugComponent(DebugSharedResources resources)
        {
            this.resources = resources;
            this.gameInfo = resources.gameInfo;
            this.commands = new List<string>();
        }
        #endregion

        #region Virtual Methods
        protected virtual void LoadContent() { }
        protected virtual void Dispose(bool disposing) { }

        public virtual void Update(GameTime gameTime) { }
        public virtual void Draw(GameTime gameTime) { }

        /// <summary>
        /// Executes a command. The class should be able to handle
        /// the given command.
        /// </summary>
        /// <param name="command">The name of the command with its arguments</param>
        public virtual void Execute(String[] command, params object[] arguments) { }

        #endregion

        #region Handle Command
        /// <summary>
        /// This method returns true if the component can Handle
        /// a given command. To register a new command the deriving
        /// class can handle use the HandleCommand method.
        /// </summary>
        /// <param name="commandName">Only the name of the command</param>
        /// <returns></returns>
        public virtual bool HandlesCommand(String commandName)
        {
            return commands.Contains(commandName.ToLowerInvariant());
        }

        /// <summary>
        /// Add a new command that this class will handle.
        /// </summary>
        /// <param name="commandName"></param>
        protected void HandleCommand(String commandName)
        {
            commands.Add(commandName.ToLowerInvariant());
        }
        #endregion

    }
}
